﻿using System;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using NIIT.SaoBacDau.Aupi.HospitalManagement.Entities;

namespace NIIT.SaoBacDau.Aupi.HospitalManagement.DataAccess
{
    public class DAO_Login
    {
        public static bool Login(Entities.Obj_Login Ac)
        {
            SqlDataAdapter sqlda = new SqlDataAdapter("HumanResources.Logins", DAO_ConnectDatabase.Connect());
            sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
            sqlda.SelectCommand.Parameters.Add("@User", SqlDbType.VarChar).Value = Ac.UserName;
            sqlda.SelectCommand.Parameters.Add("@Pass", SqlDbType.VarChar).Value = Ac.Password;
            DataTable dtable = new DataTable();
            sqlda.Fill(dtable);
            Obj_Employee emp = new Obj_Employee();
            Obj_Login login = new Obj_Login();
            if (dtable.Rows.Count == 0)
                return false;
            else
                return true;
        }

        public static Obj_Employee ProfileEmployee(Entities.Obj_Login Ac)
        {
            SqlDataAdapter sqlda = new SqlDataAdapter("HumanResources.Profile", DAO_ConnectDatabase.Connect());
            sqlda.SelectCommand.CommandType = CommandType.StoredProcedure;
            sqlda.SelectCommand.Parameters.Add("@User", SqlDbType.NVarChar).Value = Ac.UserName;
            DataTable dtable = new DataTable();
            sqlda.Fill(dtable);
            Obj_Employee emp = new Obj_Employee();
            Obj_Login login = new Obj_Login();
            if (dtable.Rows.Count == 0)
                return emp;
            else
            {
                login.UserName = dtable.Rows[0]["UserName"].ToString();
                login.Password = dtable.Rows[0]["PassWord"].ToString();
                emp.NameEmployee = dtable.Rows[0]["NameEmployee"].ToString();
                emp.Address = dtable.Rows[0]["Address"].ToString();
                emp.BirthDay = Convert.ToDateTime(dtable.Rows[0]["BirthDay"]);
                emp.Gender = Convert.ToBoolean(dtable.Rows[0]["Gender"].ToString());
                emp.Identification = Convert.ToInt32(dtable.Rows[0]["Identification"]);
                emp.Email = dtable.Rows[0]["Email"].ToString();
                emp.PhoneNumber = dtable.Rows[0]["PhoneNumber"].ToString();
            }
            return emp;
        }
    }
}
